﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CPETwit.Data.Manager;
using CPETwit.Data.Entity;

namespace CPETwit.Web.Business
{
    public class TweetBusiness
    {
        readonly TweetManager _tweetManager = new TweetManager();

        public IEnumerable<Tweet> GetUserTimeline(User user)
        {
            return _tweetManager.GetUserTimeline(user);
        }

        public IEnumerable<Tweet> GetAllTweetsRechercheParTag(string _tag)
        {
            return _tweetManager.GetAllTweetsFromTag(_tag);
        }

        public IEnumerable<Tweet> GetAllTweetsRechercheParTexte(string _texte)
        {
            return _tweetManager.GetAllTweetsFromTexte(_texte);
        }

        public void SaveTweet(User user, Message message)
        {
            Tweet t = new Tweet();
            t.twitter = user.id;
            t.creator = user.id;
            t.message = message.id;
            t.tweetdate = DateTime.Now;
            _tweetManager.CreateTweet(t);
        }

        public void SaveReTweet(User user, Tweet tweet)
        {
            Tweet t = new Tweet();
            t.twitter = user.id;
            t.creator = tweet.CreatorProperty.id;
            t.userfrom = tweet.twitter;
            t.message = tweet.message;
            t.tweetdate = DateTime.Now;
            _tweetManager.CreateTweet(t);
        }

        public void UndoReTweet(User user, Tweet tweet)
        {
            _tweetManager.DeleteTweet(tweet);
        }

        public IEnumerable<Tweet> getTweetFromId(long id)
        {
            return _tweetManager.getTweetFromId(id);
        }

        public IEnumerable<Tweet> GetAllTweetsByPublisher(string texte)
        {
            return _tweetManager.GetAllTweetsByPublisher(texte);
        }

        public IEnumerable<Tweet> GetAllTweetsByUserId(long id)
        {
            return _tweetManager.GetAllTweetsByUserId(id);
        }

       
    }
}
